package com.newasia.server.common.strategy.dataConversion;

import com.newasia.server.dal.entitys.History;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LiChong
 * @description 针对数据解析所调用的服务决定执行的策略
 * @date 2020/5/22
 */

public class DataConversionStrategy {

    public static final String MONITOR_DETAIL_DATA = "MonitorDetailServiceImpl";
    public static final String MONITOR_DETAIL_BAK_DATA = "MonitorDetailBakServiceImpl";
    public static final String HISTORY_DATA = "HistoryServiceImpl";
    public static final String OTHER_DATA = "otherServiceImpl";

    private static Map<String,DataInvoke> strategy = new HashMap<String,DataInvoke>();

    static {
        strategy.put(MONITOR_DETAIL_DATA,new MonitorDetialData());
        strategy.put(MONITOR_DETAIL_BAK_DATA,new MonitorDetailBakData());
        strategy.put(HISTORY_DATA,new HistoryData());
        strategy.put(OTHER_DATA,new OtherData());
    }

    public static Object get(Object proxyObj, Method method, Object[] args) throws Throwable {
        String payKey = proxyObj.getClass().getSimpleName();
        if(!strategy.containsKey(payKey)){
            return strategy.get(OTHER_DATA).invoke(proxyObj,method,args);
        }
        return strategy.get(payKey).invoke(proxyObj,method,args);
    }
}
